
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :chengbiao.he
	CreateTime:2008-02-28 10:58:26
*/
public class WarehouseCategoryRelationSrv extends IHandler
{

	public WarehouseCategoryRelationSrv() 
	{
		super();
	}
	private void deleteWarehouseCategoryRelation(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		WarehouseCategoryRelation obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = WarehouseCategoryRelation.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveWarehouseCategoryRelation(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		WarehouseCategoryRelation obj;
		if((id==null)||(id.equals("")))   //add
		{
			obj = WarehouseCategoryRelation.fetch();
    	}
    	else                     //update
    	{
    		obj = WarehouseCategoryRelation.fetch(con,id);
    	}
		WarehouseCategoryRelationPageData data = (WarehouseCategoryRelationPageData)PageData.fromForm(context,WarehouseCategoryRelationPageData.class);
		context.setValue("WarehouseCategoryRelationPageData",data);
		obj.fill(data);
		obj.save(con);
	}
	private void listWarehouseCategoryRelation(DBConnection con,SrvContext context,String path) throws Exception
	{
		WarehouseCategoryRelationSearchEvent event = (WarehouseCategoryRelationSearchEvent)SearchEvent.fromForm(context,WarehouseCategoryRelationSearchEvent.class);
		context.setSessionValue("WarehouseCategoryRelationSearchEvent",event);
		context.setNextUrl(path+"WarehouseCategoryRelationList.jsp");
	}
	private void backWarehouseCategoryRelation(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"WarehouseCategoryRelationList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listWarehouseCategoryRelation"))
		{
			listWarehouseCategoryRelation(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewWarehouseCategoryRelation"))
		{
			String id = context.getString("Id",null);
			WarehouseCategoryRelation obj = WarehouseCategoryRelation.fetch(con,id);
			context.setValue("WarehouseCategoryRelation",obj);
			context.setNextUrl(path+"WarehouseCategoryRelationView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteWarehouseCategoryRelation"))
		{
			context.setErrorUrl(path+"WarehouseCategoryRelationList.jsp");
			deleteWarehouseCategoryRelation(con,context);
			backWarehouseCategoryRelation(con,context,path);
			return;
		}
		
			
		if(action_code.equalsIgnoreCase("toAddWarehouseCategoryRelation"))
		{
			WarehouseCategoryRelation obj = WarehouseCategoryRelation.fetch();
			WarehouseCategoryRelationPageData data = (WarehouseCategoryRelationPageData)PageData.fromTable(obj,WarehouseCategoryRelationPageData.class);
			context.setValue("WarehouseCategoryRelationPageData",data);
			context.setNextUrl(path+"WarehouseCategoryRelationEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateWarehouseCategoryRelation"))
		{
			String id = context.getString("Id",null);
			WarehouseCategoryRelation obj = WarehouseCategoryRelation.fetch(con,id);
			WarehouseCategoryRelationPageData data = (WarehouseCategoryRelationPageData)PageData.fromTable(obj,WarehouseCategoryRelationPageData.class);
			context.setValue("WarehouseCategoryRelationPageData",data);
			context.setNextUrl(path+"WarehouseCategoryRelationEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyWarehouseCategoryRelation"))
		{
			String id = context.getString("Id",null);
			WarehouseCategoryRelation obj = WarehouseCategoryRelation.copy(WarehouseCategoryRelation.fetch(con,id));
			WarehouseCategoryRelationPageData data = (WarehouseCategoryRelationPageData)PageData.fromTable(obj,WarehouseCategoryRelationPageData.class);
			context.setValue("WarehouseCategoryRelationPageData",data);
			context.setNextUrl(path+"WarehouseCategoryRelationEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveWarehouseCategoryRelation"))
		{
			context.setErrorUrl(path+"WarehouseCategoryRelationEdit.jsp");
			saveWarehouseCategoryRelation(con,context,loginContext);
			backWarehouseCategoryRelation(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewWarehouseCategoryRelation"))
		{
			context.setErrorUrl(path+"WarehouseCategoryRelationEdit.jsp");
			saveWarehouseCategoryRelation(con,context,loginContext);
			WarehouseCategoryRelation obj = WarehouseCategoryRelation.fetch();
			WarehouseCategoryRelationPageData data = (WarehouseCategoryRelationPageData)PageData.fromTable(obj,WarehouseCategoryRelationPageData.class);
			context.setValue("WarehouseCategoryRelationPageData",data);
			context.setNextUrl(path+"WarehouseCategoryRelationEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListWarehouseCategoryRelation"))
		{
			backWarehouseCategoryRelation(con,context,path);
			return;
		}
		
		//add by chengbiao.he start

		//add by chengbiao.he end

		Logger.throwException("WarehouseCategoryRelationSrv","unknown action_code="+action_code);
	}
}
